<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="/WEB-INF/c.tld"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="admin/Hui/lib/html5.js"></script>
<script type="text/javascript" src="admin/Hui/lib/respond.min.js"></script>
<script type="text/javascript" src="admin/Hui/lib/PIE_IE678.js"></script>
<![endif]-->
<link href="admin/Hui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="admin/Hui/css/H-ui.admin.css" rel="stylesheet"
	type="text/css" />
<link href="admin/Hui/lib/font-awesome/font-awesome.min.css"
	rel="stylesheet" type="text/css" />
<!--[if IE 7]>
<link href="admin/Hui/lib/font-awesome/font-awesome-ie7.min.css" rel="stylesheet" type="text/css" />
<![endif]-->
<link href="admin/Hui/lib/iconfont/iconfont.css" rel="stylesheet"
	type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="admin/Hui/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<script type="text/javascript" src="admin/Hui/js/jquery-1.7.2.js"></script>
<title>用户管理</title>
<style>
.navul ul li {
	float: left;
	padding-left: 5px;
	text-align: center;
}

.navul {
	width: 500px;
	height: 32px;
	margin: auto;
}
</style>
<script>
	function del() {
		if (confirm("真的要删除该条记录吗?")) {
			return true;
		} else {
			return false;
		}
	}

	function resetpwd() {
		if (confirm("确定要重置该用户密码吗?")) {
			return true;
		} else {
			return false;
		}
	}

	function moredelete() {
		var chk_value = [];
		$('input[name="check_id"]:checked').each(function() {
			chk_value.push($(this).val());
		});
		if (chk_value.length == 0) {
			alert("未选择");
		} else {
			var mes = confirm("是否删除？");
			if (mes == true) {
				$("#formdelete").submit();
			}
		}
	}
</script>
</head>
<body>
	<nav class="breadcrumb">
		<span><img src="admin/images/leftico01.png" /></span> 系统管理 <span
			class="c-gray en">&gt;</span> 用户管理 <a
			class="btn btn-success radius r mr-20"
			style="line-height: 1.6em; margin-top: 3px"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="icon-refresh"></i></a>
	</nav>
	<div class="pd-20">
		<div class="text-c">
			注册日期范围： <input type="text"
				onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})"
				id="datemin" name="datemin" class="input-text Wdate"
				style="width: 120px;"> - <input type="text"
				onfocus="WdatePicker({minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d'})"
				id="datemax" name="datemax" class="input-text Wdate"
				style="width: 120px;"> <input type="text" class="input-text"
				style="width: 250px" placeholder="输入用户名、电话、邮箱、积分" id="searchname"
				name="searchname">
			<button type="button" class="btn btn-success" id="tosubmit">
				<i class="icon-search"></i> 搜用户
			</button>
		</div>
		<div class="cl pd-5 bg-1 bk-gray mt-20">
			<span class="l"><a id="moredelete"
				class="btn btn-danger radius" onclick="moredelete()"><i
					class="icon-trash"></i> 批量删除</a> <a href="user!addModel.action"
				class="btn btn-primary radius"> <i class="icon-plus"></i> 添加用户
			</a></span> <span class="r"> 共有数据：<strong>${page.total }</strong> 条
			</span>
		</div>
		<form action="user!moredelete.action" method="post" id="formdelete">
			<table
				class="table table-border table-bordered table-hover table-bg table-sort">
				<thead>

					<tr class="text-c">
						<th width="25"><input type="checkbox" name="" value=""></th>
						<th width="80">ID</th>
						<th width="100">用户名</th>
						<th width="50">性别</th>
						<th width="90">手机</th>
						<th width="100">地址</th>
						<th width="130">注册时间</th>
						<th width="150">积分</th>
						<th width="120">操作</th>
					</tr>

				</thead>
				<tbody>
					<s:iterator value="userList">
						<tr class="text-c">
							<td><input type="checkbox" value="${user_id }"
								name="check_id"></td>
							<td>${user_id }</td>
							<td><u style="cursor: pointer" class="text-primary"
								onclick="user_show('10001','400','','${user_name }','user!show.action?user_id=${user_id }')">${user_name }</u></td>
							<td><s:if test="user_sex==1">男</s:if> <s:elseif
									test="user_sex==0">女</s:elseif></td>
							<td>${user_phone }</td>
							<td>${user_addr }</td>
							<td>${user_regtime }</td>
							<td>${user_scose }</td>
							<td class="f-14 user-manage"><a title="编辑"
								href="user!edit.action?user_id=${user_id }" class="ml-5"
								style="text-decoration: none"> <i class="icon-edit"></i></a>&nbsp;<a
								href="user!resetpwd.action?user_id=${user_id }"
								style="text-decoration: none;" class="resetpwd ml-5"
								onclick="return resetpwd()" title="重置密码"><i class="icon-key"></i></a>
								<a title="删除" href="user!delete.action?user_id=${user_id }"
								onclick="return del()" class="ml-5"
								style="text-decoration: none"> <i class="icon-trash"></i>
							</a></td>
						</tr>
					</s:iterator>
				</tbody>
			</table>
		</form>

	</div>

	<script>
		$("#tosubmit").on("click", function(){
			$.post("user!search.action", {
				searchname: $("#searchname").val(),
				datemin: $("#datemin").val(),
				datemax: $("#datemax").val()
			}, function(data){
				var json = JSON.parse(data);
				if (json.page.currentPage != 1) {
					$("#first").show();
				} else {
					$("#first").hide();
					$("#next").attr("href",
							"javascript:showPage(2)");
					$("#last").show();
				}
				if (json.page.hasPrePage) {
					$("#prev").show();
					$("#prev").attr(
							"href",
							"javascript:showPage("
									+ (json.page.currentPage - 1)
									+ ")");
				} else {
					$("#prev").hide();
				}
				if (json.page.hasNextPage) {
					$("#next").show();
					$("#next").attr(
							"href",
							"javascript:showPage("
									+ (json.page.currentPage + 1)
									+ ")");
				} else {
					$("#next").hide();
					$("#last").hide();
				}
				if (json.page.currentPage < json.page.totalPage) {
					$("#last").show();
				} else {
					$("#last").hide();
				}
				$("#current").html("第" + json.page.currentPage + "页");
				$("#total").html("共" + json.page.totalPage + "页");
				$("tbody").empty();
				console.log(json.list);
				$.each(json.list,function(n, obj) {
					var strhtml = "<tr class='text-c'>";
					strhtml += "<td><input type='checkbox' name='chk_id' value='" + obj.user_id + "' /></td>";
					strhtml += "<td>" + obj.user_id
							+ "</td>";
					strhtml += "<td>"
							+ "<u style='cursor: pointer' class='text-primary'"
							+ "onclick=user_show('10001','400','','" + (obj.user_name==null?'':obj.user_name)
							+ ",'user!show.action?user_id=${user_id }')>" +  (obj.user_name==null?'':obj.user_name) +"</u>"
							+ "</td>";
					strhtml += "<td>"
							+ (obj.user_sex==null?'':obj.user_sex)
							+ "</td>";
					strhtml += "<td>"
							+ (obj.user_phone==null?'':obj.user_phone)
							+ "</td>";
					strhtml += "<td>"
							+ (obj.user_addr==null?'':obj.user_addr)
							+ "</td>";
					strhtml += "<td>"
							+ (obj.user_regtime==null?'':obj.user_regtime)
							+ "</td>";
					strhtml += "<td>"
							+ (obj.user_scose==null?'':obj.user_scose)
							+ "</td>";
					strhtml += "<td class='f-14 user-manage'><a title='编辑'"
							+"href='user!edit.action?user_id=" + obj.user_id + "'class='ml-5'"
							+"style='text-decoration: none'> <i class='icon-edit'></i></a>" 
							+"&nbsp;&nbsp;<a href='user!resetpwd.action?user_id=" + obj.user_id  +
							+"'style='text-decoration: none;' class='resetpwd ml-5'"
							+"onclick='return resetpwd()' title='重置密码'><i class='icon-key'></i></a>"
							+"&nbsp;<a title='删除' href='user!delete.action?user_id=" + obj.user_id 
							+"'onclick='return del()' class='ml-5' style='text-decoration: none'>"
							+"<i class='icon-trash'></i></a></td>";
					strhtml += "</tr>";
					$("tbody").append(strhtml);
				});
			});
		});
		function showPage(page) {
			$.ajax({
					type : "POST",
					url : "user!search.action",
					data : {
						"curPage" : page,
						"searchname" : $("#searchname").val(),
						"datemin" : $("#datemin").val(),
						"datemax" : $("#datemax").val(),
					},
					success : function(data, status) {
						var json = JSON.parse(data);
						if (json.page.currentPage != 1) {
							$("#first").show();
						} else {
							$("#first").hide();
							$("#next").attr("href",
									"javascript:showPage(2)");
							$("#last").show();
						}
						if (json.page.hasPrePage) {
							$("#prev").show();
							$("#prev").attr(
									"href",
									"javascript:showPage("
											+ (json.page.currentPage - 1)
											+ ")");
						} else {
							$("#prev").hide();
						}
						if (json.page.hasNextPage) {
							$("#next").show();
							$("#next").attr(
									"href",
									"javascript:showPage("
											+ (json.page.currentPage + 1)
											+ ")");
						} else {
							$("#next").hide();
							$("#last").hide();
						}
						if (json.page.currentPage < json.page.totalPage) {
							$("#last").show();
						} else {
							$("#last").hide();
						}
						$("#current").html("第" + json.page.currentPage + "页");
						$("#total").html("共" + json.page.totalPage + "页");
						$("tbody").empty();
						console.log(json.list);
						$.each(json.list,function(n, obj) {
							var strhtml = "<tr class='text-c'>";
							strhtml += "<td><input type='checkbox' name='chk_id' value='" + obj.user_id + "' /></td>";
							strhtml += "<td>" + obj.user_id
									+ "</td>";
							strhtml += "<td>"
									+ "<u style='cursor: pointer' class='text-primary'"
									+ "onclick=user_show('10001','400','','" + (obj.user_name==null?'':obj.user_name)
									+ "','user!show.action?user_id="+ obj.user_id + "')>" +  (obj.user_name==null?'':obj.user_name) +"</u>"
									+ "</td>";
							strhtml += "<td>"
									+ (obj.user_sex==null?'':obj.user_sex)
									+ "</td>";
							strhtml += "<td>"
									+ (obj.user_phone==null?'':obj.user_phone)
									+ "</td>";
							strhtml += "<td>"
									+ (obj.user_addr==null?'':obj.user_addr)
									+ "</td>";
							strhtml += "<td>"
									+ (obj.user_regtime==null?'':obj.user_regtime)
									+ "</td>";
							strhtml += "<td>"
									+ (obj.user_scose==null?'':obj.user_scose)
									+ "</td>";
							strhtml += "<td class='f-14 user-manage'><a title='编辑'"
									+"href='user!edit.action?user_id=" + obj.user_id  + "'class='ml-5'"
									+"style='text-decoration: none'> <i class='icon-edit'></i></a>" 
									+"&nbsp;&nbsp;<a href='user!resetpwd.action?user_id=" + obj.user_id +
									+"'style='text-decoration: none;' class='resetpwd ml-5'"
									+"onclick='return resetpwd()' title='重置密码'><i class='icon-key'></i></a>"
									+"&nbsp;<a title='删除' href='user!delete.action?user_id=" + obj.user_id
									+"'onclick='return del()' class='ml-5' style='text-decoration: none'>"
									+"<i class='icon-trash'></i></a></td>";
							strhtml += "</tr>";
							$("tbody").append(strhtml);
						});
					}
				});
		}
	</script>

	<div class="navul">
		<input type="hidden" id="maxPage" value="${page.totalPage }" />
		<ul>
			<li><a id="first" style="display: none;"
				class="btn btn-danger radius" href="javascript:showPage(1)">首页</a> <c:if
					test="${page.currentPage!=1 }">
					<a id="first" class="btn btn-danger radius"
						href="javascript:showPage(1)">首页</a>
				</c:if></li>
			<li><a id="prev" style="display: none;"
				class="btn btn-danger radius"
				href="javascript:showPage(${page.currentPage-1 })">上一页</a> <c:if
					test="${page.hasPrePage }">
					<a id="prev" class="btn btn-danger radius"
						href="javascript:showPage(${page.currentPage-1 })">上一页</a>
				</c:if></li>
			<li><c:if test="${page.hasNextPage }">
					<a id="next" class="btn btn-danger radius"
						href="javascript:showPage(${page.currentPage+1 })">下一页</a>
				</c:if></li>
			<li><c:if test="${page.currentPage < page.totalPage }">
					<a id="last" class="btn btn-danger radius"
						href="javascript:showPage(${page.totalPage })">最后一页</a>
				</c:if></li>
			<li><span class="btn btn-default disabled" id="current">第${page.currentPage }
					页</span></li>
			<li><span class="btn btn-default disabled" id="total">共
					${page.totalPage } 页</span></li>
		</ul> 
	</div>
	<script type="text/javascript" src="admin/Hui/lib/jquery.min.js"></script>
	<script type="text/javascript"
		src="admin/Hui/lib/layer1.8/layer.min.js"></script>
	<script type="text/javascript" src="admin/Hui/lib/laypage/laypage.js"></script>
	<script type="text/javascript"
		src="admin/Hui/lib/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript"
		src="admin/Hui/lib/jquery.dataTables.min.js"></script>
	<script type="text/javascript" src="admin/Hui/js/H-ui.js"></script>
	<script type="text/javascript" src="admin/Hui/js/H-ui.admin.js"></script>
	<script type="text/javascript" src="admin/Hui/js/H-ui.admin.doc.js"></script>
	<script type="text/javascript">
		$('.table-sort').dataTable({
			"lengthMenu" : false,//显示数量选择 
			"bFilter" : false,//过滤功能
			"bPaginate" : false,//翻页信息
			"bInfo" : false,//数量信息
			"aaSorting" : [ [ 1, "desc" ] ],//默认第几个排序
			"bStateSave" : true,//状态保存
			"aoColumnDefs" : [
			//{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
			{
				"orderable" : false,
				"aTargets" : [ 0, 2, 5, 8 ]
			} // 制定列不参与排序
			]
		});

		function user_resetpwd(id) {
			/* layer.confirm('确认要删除吗？',function(index){
				alert("123");
			}); */
			if (confirm('确认要重置密码吗？')) {
				$(".resetpwd").attr("href",
						"user!resetpwd.action?user_id=" + id);
				layer.msg('重置成功!', 2);
			}
		}
	</script>
	<script>
		var _hmt = _hmt || [];
		(function() {
			var hm = document.createElement("script");
			hm.src = "//hm.baidu.com/hm.js?080836300300be57b7f34f4b3e97d911";
			var s = document.getElementsByTagName("script")[0];
			s.parentNode.insertBefore(hm, s);
		})();
		var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://"
				: " http://");
		document
				.write(unescape("%3Cscript src='"
						+ _bdhmProtocol
						+ "hm.baidu.com/h.js%3F080836300300be57b7f34f4b3e97d911' type='text/javascript'%3E%3C/script%3E"));
	</script>
</body>
</html>
